package com.jsits.v2x.common.connection.socket;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class MessageHandler extends IoHandlerAdapter
{
	/*
	 * Socket连接类
	 */
	private SocketBase socketBase;
	
	public void setSocketBase(SocketBase socketBase) 
	{
		this.socketBase = socketBase;
	}
	
	public void exceptionCaught(IoSession session, Throwable cause)	throws Exception 
	{
		super.exceptionCaught(session, cause);
	}

	public void messageReceived(IoSession session, Object message) throws Exception 
	{
		//将消息转化为自定义类型，并调用客户端消息处理接口处理消息
		socketBase.onMessageReceive((SocketMessage)message, session);
	}

	public void messageSent(IoSession session, Object message) throws Exception 
	{
		super.messageSent(session, message);
	}

	public void sessionClosed(IoSession session) throws Exception 
	{
		super.sessionClosed(session);
	}

	public void sessionCreated(IoSession session) throws Exception 
	{
		super.sessionCreated(session);
	}

	public void sessionIdle(IoSession session, IdleStatus status) throws Exception 
	{
		super.sessionIdle(session, status);
	}

	public void sessionOpened(IoSession session) throws Exception 
	{
		super.sessionOpened(session);
	}
}
